<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />

<style>

</style>

</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">借阅申请</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">合同号</div>
						<div class="field">
							${arcMgrMainVO.contractNo}
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">交接单名称</div>
						<div class="field">
							${arcMgrMainVO.arcReceiptName}
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">省公司档案袋编号</div>
						<div class="field">${arcMgrMainVO.portfolioNumberProvince}
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">总部档案袋编号</div>
						<div class="field">${arcMgrMainVO.portfolioNumber}
						</div>
					</div>
					
					<div class="caption">
						<span class="title">合同资料、承租人资料、担保人资料  ${arcMgrMainVO.cstNm}  ${arcMgrMainVO.contractNo}</span>
					</div>
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
							<div id="gridContract" class="sq-grid"></div>
						</div>
					</div>
					
					<div class="caption">
						<span class="title">权证资料</span>
					</div>
					<c:forEach items="${paySchNoArray}" var="item">
						<div class="fieldBox col_100">
						${item }
							<div style="width: 98%; margin-left: 1%;">
								<div id="gridPay${item }" class="sq-grid"></div>
							</div>
						</div>
					</c:forEach>
					
					<div class="caption">
						<span class="title">借阅历史</span>
					</div>
					
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
							<div id="gridPostInfo" class="sq-grid"></div>
						</div>
					</div>
					
				</div>
				
				
			</form>
		</div>
	</div>
	<script type="text/javascript">
	     var  contractNo = "${arcBorrowMainVO.contractNo}";//合同号
	     var  paySchNoList = "${arcBorrowMainVO.paySchNoList}";//多个支付表号
	     
		$(function() {
			$("#ligerForm").ligerForm();
			
			//初始化合同明细和权证资料明细
			initGrid();
			
			//初始化借用历史
			createPostInfoGrid("gridPostInfo","300");
			
	    });
		
		function initGrid(){
			//1、初始化合同明细
			if(contractNo !="") {
				createGrid("gridContract",1,contractNo,"");
			}
			
			//2、初始化权证资料明细
			if(paySchNoList !="") {
				var paySchNoArray = paySchNoList.split(";");
				for(var i=0;i<paySchNoArray.length;i++) {
					createGrid("gridPay"+paySchNoArray[i],2,contractNo,paySchNoArray[i]);//创建ligerGrid
				}
			}
		}
	     
		function createGrid(gridId,arcLevel,contractNo,paylistCode){
		     
			$("#"+gridId).ligerGrid({
				url:'<%=path%>/archive/arcBorrowMain/arcMgrDetailList.do?arcLevel='+arcLevel+'&contractNo='+contractNo+'&paylistCode='+paylistCode,
				method:'get',
				columns:[
					{ display: '权证类别', name: 'fileFlagNm',type:'text'},
					{ display: '权证名称', name: 'fileName',type:'text'},
					{display:'资料类型', name: 'dossierTempNm'},
					{display:'归档地点', name: 'arcReceiptDetailVO.arcPlaceNm'},
					//{display:'存档份数',name: 'dossierCountT',type:'int'},
					{display:'状态',name: 'borrowStatusNm'},
					/* {display:'操作',
						width:220,
						render:function (rowdata, rowindex, value){
							var h="";
								h+='<a class="sq-button-hasicon" href="javascript:viewTotal(';
				            	h+="'"+rowdata.contractNo+"',";
				            	h+="'"+rowdata.paySchNo+"'";
				                h+=")\"><i class='sqBtnIco_4'></i>借阅记录</a>";
			                
							return h;
						}
					}, */
					
				],onBeforeSubmitEdit: function (e) {
		        
		        },
			    enabledEdit: false,
				usePager: false,//是否有分页便签
				isScroll: true,//是否有滚动条
				root:'rows',
				record:'total',
				hideLoadButton:false,
				frozen: false,
				width:'100%',
				height:'300',
				heightDiff:-2,
				checkbox:false,//列表是否有选择框
				rownumbers:true,//列表是否有行号
				selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
				//选择行事件
				onSelectRow: function(rowdata, rowid, rowobj){
					
				},
				//取消选择行事件
				onUnSelectRow : function(rowdata, rowid, rowobj){
				},
				onBeforeCheckRow: function (checked, data, rowindex, rowobj) {
	            },
	            detail: {
	                height: 'auto',
	                onShowDetail: showDetail_grid
	            }
	            //onBeforeEdit: f_onBeforeEdit0,
			});
		}
		
		 //逾期明细列表
	    function showDetail_grid(row, detailPanel, callback) {
	    
	     var gridBox = document.createElement('div');
	        $(gridBox).css('margin', 10);
	        $(detailPanel).css({
	            'padding': 10,
	            'box-sizing': 'border-box'
	        }).append(gridBox);
	        detailGrid = $(gridBox).ligerGrid({
	        	 url:'<%=path%>/archive/arcBorrowMain/borrowRecord.do?arcMgrDetailId='+ row.id,
	            method: 'get',
	            columns: [
	                      { display: '申请人', name: 'CRT_USR_ID_NM',align:'center' , enabledSort:false},
				          { display: '申请时间', name: 'CRT_TM_',  render:renderDate, enabledSort:false},
				          {display:'是否归还/计划归还日期', 
							  render: function (item) {
				                    return item.ORIGINAL_RETURN_NM+" "+(item.RETURN_DATE_==null?"":item.RETURN_DATE_);
				                }
						},
						{display:'归还状态', name: 'RETURN_STATE_NM'},
						{display:'实际归还日期', 
							  render: function (item) {
				                    return item.REAL_RETURN_DATE_;
				                }
						},
						 { display: '流程编号', name: 'P_NO',  width:150,
			            	render: function (rowdata, rowindex, value, column) { 
		            			if(StringUtils.isEmpty(value)){
		                			value = "";
		                		}
		            			var h = '';
		            		    h='<a href="javascript:showFlow(';
		                        h+="'"+rowdata.P_INST_ID+"',";
		                        h+="'"+rowdata.AUD_STS_CD+"',";
		                        h+="'"+rowdata.DATA_ID+"'";
		                        h+=')">'+value+'</a>'
		                        return h;
		            		}
			            }, {display:'操作',
							width:220,
							render:function (rowdata, rowindex, value){
								var h="";
									if(rowdata.canDelayApply) {
										h+='<a class="sq-button-hasicon" href="javascript:delayApply(';
						            	h+="'"+rowdata.DATA_ID+"'";
						                h+=")\"><i class='sqBtnIco_4'></i>延期申请</a>";
									}
				                
								return h;
							}
						},
	            ],
	            root: 'rows',
	            hideLoadButton: true,
	            width: '100%',
	            height: 'auto',
	            isScroll: false,
	            rownumbers: true,  //显示序号
	            checkbox: false,
	            allowUnSelectRow: true,
	            alternatingRow: true,
	            onAfterShowData: callback,
	            frozen: false,
	            usePager: false
	        });
	    }
		
		function createPostInfoGrid(gridId,_height){
		     
			$("#"+gridId).ligerGrid({
				url:'<%=path%>/archive/arcBorrowMain/borrowHistoryPage.do?contractNo='+contractNo+'&paySchNo='+paySchNoList,
				method:'get',
				columns:[
				         { display: '流程编号', name: 'P_NO',  width:150,
				            	render: function (rowdata, rowindex, value, column) { 
			            			if(StringUtils.isEmpty(value)){
			                			value = "";
			                		}
			            			var h = '';
			            		    h='<a href="javascript:showFlow(';
			                        h+="'"+rowdata.P_INST_ID+"',";
			                        h+="'"+rowdata.AUD_STS_CD+"',";
			                        h+="'"+rowdata.DATA_ID+"'";
			                        h+=')">'+value+'</a>'
			                        return h;
			            		}
				            },
							{ display: '借阅类型', name: 'BORROW_TYPE_NM',type:'text'},
				            { display: '申请人', name: 'CRT_USR_ID_NM',align:'center' , enabledSort:false},
				            { display: '申请时间', name: 'CRT_TM_',  render:renderDate, enabledSort:false},
							{ display: '地址类型', name: 'ARC_APP_BUSS_TYPE_NM',type:'text',
				            	render: function (rowdata, rowindex, value){
			                        var h='<span class="gridTip" title="'+ value +'">'+ value +'</span>'
			                        return h;
			                    }},
							{ display: '收件人（工号）', name: 'ID_CARD',type:'text'},
							{ display: '收件人（姓名）', name: 'RECIPIENT',type:'text'},
							{ display: '联系电话', name: 'MOBILE',type:'text'},
							{ display: '接收方式', name: 'SEND_TYPE_NM',type:'text'},
							{ display: '地址', name: 'SEND_ADDR',type:'text'},
							{ display: '物流公司', name: 'SEND_COMPANY_NM',type:'text'},
							{ display: '快递单号', name: 'SEND_NUM',type:'text'},
						],
				onBeforeSubmitEdit: function (e) {
		        
		        },
			    enabledEdit: false,
				usePager: true,//是否有分页便签
				isScroll: true,//是否有滚动条
				root:'rows',
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:_height,
				heightDiff:-2,
				//checkbox:true,//列表是否有选择框
				rownumbers:true,//列表是否有行号
				selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
				 onAfterShowData: function () {
		                $(".gridTip").grid_ligerTip();
		                //SetIframe_height ();
		                /*$("#"+gridId).rowspan('P_NO');
		                $("#"+gridId).rowspan('BORROW_TYPE_NM');
		                $("#"+gridId).rowspan('CRT_USR_ID_NM');
		                $("#"+gridId).rowspan('CRT_TM_');*/
		            },
				//选择行事件
				onSelectRow: function(rowdata, rowid, rowobj){
					
				},
				//取消选择行事件
				onUnSelectRow : function(rowdata, rowid, rowobj){
				},
				onBeforeCheckRow: function (checked, data, rowindex, rowobj) {
	            }
			});
		}
		
		
		function renderDate(rowdata, index, value){
			var dateStr = "";
			if(value != null && value !=""){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr;
		}	
		
		   function showFlow(_pInstId,_audStsCd,_dataId){
		    	
		    	if(StringUtils.isEmpty(_pInstId)){
					UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
					return;
				}
		    	
		    	var _formUrl ="/archive/arcBorrowMain/view.do?id=";
		    	
				var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_dataId+"&formUrl="+_formUrl;
				Add_navTab('arc_borrrow_flow'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
		    }
		   
		   function delayApply(id){
		    	
				var url = "<%=path%>/archive/arcBorrowMain/delayApply.do?from=delayApply&id="+id;
				Add_navTab('delayApply'+id,'延期申请',url);
		    }
	</script>
</body>
</html>